package hfuu.com.cn.teasystemapp;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import hfuu.com.cn.teasystemapp.bean.operatesq;
import hfuu.com.cn.teasystemapp.util.listviewutil;

/**
 * Created by git on 2018/5/26.
 */

/**
 * 列表显示
 */
public class sqloglist extends Activity {
    private List<HashMap<String, Object>> sqlogdata;
    List<operatesq> operatesqlist;
    SimpleAdapter adapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sqlogdata=new ArrayList<HashMap<String, Object>>();
        Intent old=getIntent();
        setContentView(R.layout.sqlist);
        operatesqlist=new ArrayList<operatesq>();
        operatesqlist=(List<operatesq>) old.getSerializableExtra("sqlist");
        if(operatesqlist.size()>0) {
            for (operatesq sq :
                    operatesqlist) {
                HashMap<String, Object> item = new HashMap<String, Object>();
                item.put("teaname", sq.getWarehouseteax().getWarehouseTeaname());
                item.put("wd", sq.getOperateWd());
                item.put("time", sq.getOperateTotaltime());
                item.put("isfocus", false);
                sqlogdata.add(item);
            }
            ListView sqloglist = (ListView) findViewById(R.id.sqloglist);
            ImageView back = (ImageView) findViewById(R.id.back);
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            adapter = new SimpleAdapter(this, sqlogdata, R.layout.sqlogitem, new String[]{"teaname", "wd", "time"}, new int[]{R.id.teaname, R.id.wd, R.id.time}) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = super.getView(position, convertView, parent);
                    Boolean isFocus = (Boolean) sqlogdata.get(position).get("isfocus");

                    if (isFocus) {
                        view.setBackgroundColor(getResources().getColor(R.color.tv_gray));
                    } else {
                        view.setBackgroundColor(Color.WHITE);
                    }
                    return view;
                }
            };
            sqloglist.setAdapter(adapter);
            listviewutil.setListViewHeightBasedOnChildren(sqloglist);
        }

    }
}
